package com.zhiyou100.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhiyou100.model.Visitors;
import com.zhiyou100.service.VisitorsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author YQL
 */
@Controller
@RequestMapping("/visitors")
public class VisitorsController {
    @Autowired
    private VisitorsService visitorsService;

    @GetMapping({"/page/{pageNumber}/{vstatus}", "/page"})
    public String getVisitorsPage(Model model
            , @PathVariable(value = "pageNumber"
            , required = false)Integer pageNumber
            , @PathVariable(value = "vstatus"
            , required = false)Integer vstatus) {

        Page<Visitors> page = visitorsService.getVisitorsPage(pageNumber, vstatus);
        model.addAttribute("page", page);
        return "list";
    }

    @GetMapping({"/now/{pageNumber}", "/now"})
    public String getNow(Model model
            , @PathVariable(value = "pageNumber"
            , required = false)Integer pageNumber
            , @PathVariable(value = "vstatus"
            , required = false)Integer vstatus) {
        List<Visitors> list = visitorsService.getNow();
        model.addAttribute("list", list);
        return "list";
    }
    @GetMapping({"/record/{pageNumber}", "/record"})
    public String getRecord(Model model
            , @PathVariable(value = "pageNumber"
            , required = false)Integer pageNumber) {
        Page<Visitors> page = visitorsService.getRecord(pageNumber);
        model.addAttribute("page", page);
        return "list";
    }
}
